package com.ruoyi.business.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.DispatchList;
import com.ruoyi.business.service.IDispatchListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.Arrays;
import java.util.List;

/**
 * DispatchListController
 *
 * @author liutietou
 * @since 1.0 2025-07-19
 */
@RestController
@RequestMapping("/business/DispatchList")
public class DispatchListController extends BaseController {
    @Autowired
    private IDispatchListService dispatchListService;

    /**
     * 查询DispatchList列表
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:list')")
    @GetMapping("/list")
    public TableDataInfo list(DispatchList dispatchList) {
        Page<DispatchList> page = dispatchListService.findDispatchListPage(dispatchList);
        return getDataTable(page);
    }

    /**
     * 导出DispatchList列表
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:export')")
    @Log(title = "DispatchList", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DispatchList dispatchList) {
        List<DispatchList> list = dispatchListService.findDispatchListList(dispatchList);
        ExcelUtil<DispatchList> util = new ExcelUtil<>(DispatchList.class);
        return util.exportExcel(list, "DispatchList");
    }

    /**
     * 获取DispatchList详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:query')")
    @GetMapping(value = "/{dlid}")
    public AjaxResult getInfo(@PathVariable("dlid") Integer dlid) {
        return AjaxResult.success(dispatchListService.findById(dlid));
    }


    @GetMapping(value = "/cdlcode")
    public AjaxResult getCdlcode() {
        return   AjaxResult.success(dispatchListService.getCdlcode());
    }

    /**
     * 新增DispatchList
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:add')")
    @Log(title = "DispatchList", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchList dispatchList) {
        dispatchListService.save(dispatchList);
        return AjaxResult.success();
    }

    /**
     * 修改DispatchList
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:edit')")
    @Log(title = "DispatchList", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchList dispatchList) {
        dispatchListService.save(dispatchList);
        return AjaxResult.success();
    }

    /**
     * 删除DispatchList
     */
    @PreAuthorize("@ss.hasPermi('business:DispatchList:remove')")
    @Log(title = "DispatchList", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dlids}")
    public AjaxResult remove(@PathVariable Integer[] dlids) {
        dispatchListService.deleteByIds(Arrays.asList(dlids));
        return AjaxResult.success();
    }
}
